import { getYearAndWeek, getMondayOfWeek } from '@/util/helpers';

export const getRawMaterialOtherOption = (safe) => {
  return {
    labelPosition: 'right',
    labelWidth: 120,
    // menuBtn: true,
    submitBtn: false,
    submitText: '生成标签',
    emptyBtn: false,
    menuPosition: 'right',
    column: [
      {
        label: '收料记录',
        prop: 'receiveRecord',
        span: 12,
        type: 'search',
        readonly: true,
        placeholder: '请选择 收料记录',
        rules: [
          {
            required: true,
            trigger: 'submit',
            validator: (rule, value, callback) => {
              callback();
            }
          }
        ],
        appendClick: () => {
          safe.openCommonModal('otherReceiveMoal');
        }
      },
      {
        label: '供应商名称',
        prop: 'vendorName',
        span: 12,
        disabled: true,
        placeholder: '供应商名称'
      },
      {
        label: '物料编码',
        prop: 'partNo',
        span: 12,
        disabled: true,
        placeholder: '请选择 物料编码'
      },
      {
        label: '物料名称',
        prop: 'partName',
        span: 12,
        disabled: true,
        placeholder: '物料名称'
      },
      {
        label: '物料规格',
        prop: 'partModel',
        span: 12,
        disabled: true,
        placeholder: '物料规格'
      },
      {
        label: '接收数量',
        prop: 'receiveQuantity',
        disabled: true,
        placeholder: '接收数量',
        span: 12
      },
      {
        label: '单位',
        prop: 'uom',
        disabled: true,
        placeholder: '单位',
        span: 12
      },
      {
        label: 'D/C',
        prop: 'partLotNo'
      },
      {
        label: '品牌',
        prop: 'materialBrand'
      },
      {
        label: '供应商批次',
        prop: 'vendorLotNo',
        span: 12
      },
      {
        label: '备注',
        prop: 'remark',
        span: 12
      },
      {
        label: '生产日期',
        prop: 'vendorDate',
        type: 'date',
        format: 'yyyy-MM-dd',
        valueFormat: 'yyyy-MM-dd',
        span: 12,
        placeholder: '请选择 生产日期',
        rules: [
          {
            required: true,
            trigger: 'submit',
            validator: (rule, value, callback) => {
              callback();
            }
          }
        ],
        change: ({ column, value }) => {
          safe.rawMaterialOtherForm.week = value ? getYearAndWeek(value) : '';
        }
      },
      {
        label: 'MPQ',
        prop: 'mpq',
        span: 12,
        rules: [
          {
            required: true,
            trigger: 'submit',
            validator: (rule, value, callback) => {
              callback();
            }
          }
        ]
      },
      {
        label: '序列号规则',
        prop: 'sequenceName',
        type: 'search',
        placeholder: '请选择 条码规则',
        span: 12,
        disabled: true,
        rules: [
          {
            required: true,
            trigger: 'submit',
            validator: (rule, value, callback) => {
              callback();
            }
          }
        ],
        appendClick: () => {
          safe.openSerialnoCommonModal();
        }
      },
      {
        label: '本次生成数量',
        prop: 'generationQuantity',
        span: 12,
        placeholder: '请输入本次生成数量',
        rules: [
          {
            required: true,
            trigger: 'submit',
            validator: (rule, value, callback) => {
              if (Number(value.generationQuantity) >= Number(value.receiveQuantity)) {
                callback('本次生成数量需要小于等于接受数量');
              } else {
                callback();
              }
            }
          }
        ],
        change: ({ value }) => {
          if (value) {
            safe.preview(safe.rawMaterialOtherForm, value);
          } else {
            safe.$set(safe.sequenceRuleInfo, 'sequenceNo', '');
            safe.$set(safe.sequenceRuleInfo, 'quantity', '');
            safe.$set(safe.sequenceRuleInfo, 'sequenceNumberFrom', '');
            safe.$set(safe.sequenceRuleInfo, 'snLength', '');
            safe.$set(safe.sequenceRuleInfo, 'sequenceNumberTo', '');
          }
        }
      }
    ]
  };
};

export const getOption = (safe) => {
  return {
    labelPosition: 'right',
    labelWidth: 120,
    // menuBtn: true,
    submitBtn: false,
    submitText: '生成标签',
    emptyBtn: false,
    menuPosition: 'right',
    column: [
      {
        label: '收料记录',
        prop: 'receiveRecord',
        span: 12,
        type: 'search',
        readonly: true,
        placeholder: '请选择 收料记录',
        rules: [
          {
            required: true,
            trigger: 'submit',
            validator: (rule, value, callback) => {
              callback();
            }
          }
        ],
        appendClick: () => {
          safe.openCommonModal('otherReceiveMoal');
        }
      },
      {
        label: '供应商名称',
        prop: 'vendorName',
        span: 12,
        disabled: true,
        placeholder: '供应商名称'
      },
      {
        label: '物料编码',
        prop: 'partNo',
        span: 12,
        disabled: true,
        placeholder: '请选择 物料编码'
      },
      {
        label: '物料名称',
        prop: 'partName',
        span: 12,
        disabled: true,
        placeholder: '物料名称'
      },
      {
        label: '物料规格',
        prop: 'partModel',
        span: 12,
        disabled: true,
        placeholder: '物料规格'
      },
      {
        label: '接收数量',
        prop: 'receiveQuantity',
        disabled: true,
        placeholder: '接收数量',
        span: 12
      },
      {
        label: '单位',
        prop: 'uom',
        disabled: true,
        placeholder: '单位',
        span: 12
      },
      {
        label: 'D/C',
        prop: 'partLotNo'
      },
      {
        label: '品牌',
        prop: 'materialBrand'
      },
      {
        label: '供应商批次',
        prop: 'vendorLotNo',
        span: 12
      },
      {
        label: '备注',
        prop: 'remark',
        span: 12
      },
      {
        label: '生产日期',
        prop: 'vendorDate',
        type: 'date',
        format: 'yyyy-MM-dd',
        valueFormat: 'yyyy-MM-dd',
        span: 12,
        placeholder: '请选择 生产日期',
        rules: [
          {
            required: true,
            trigger: 'submit',
            validator: (rule, value, callback) => {
              callback();
            }
          }
        ],
        change: ({ column, value }) => {
          safe.form.week = value ? getYearAndWeek(value) : '';
        }
      },
      {
        label: '序列号规则',
        prop: 'sequenceName',
        type: 'search',
        placeholder: '请选择 条码规则',
        span: 12,
        disabled: true,
        rules: [
          {
            required: true,
            trigger: 'submit',
            validator: (rule, value, callback) => {
              callback();
            }
          }
        ],
        appendClick: () => {
          safe.openSerialnoCommonModal();
        }
      },
      {
        label: '本次生成数量',
        prop: 'generationQuantity',
        span: 12,
        placeholder: '请输入本次生成数量',
        rules: [
          {
            required: true,
            trigger: 'submit',
            validator: (rule, value, callback) => {
              if (Number(value.generationQuantity) >= Number(value.receiveQuantity)) {
                callback('本次生成数量需要小于等于接受数量');
              } else {
                callback();
              }
            }
          }
        ]
      }
    ]
  };
};

export const getBigPackOption = (self) => {
  return {
    height: 300,
    calcHeight: 30,
    border: true,
    index: true,
    indexLabel: '序号',
    viewBtn: false,
    selection: true,
    dialogClickModal: false,
    addBtn: false,
    editBtn: false,
    delBtn: false,
    tip: false,
    refreshBtn: false, //刷新按钮是否显示
    columnBtn: false, //控制表格列是否显示按钮是否显示
    column: [
      {
        label: '包装条码',
        prop: 'sequenceNumber'
      },
      {
        label: '包装层级',
        prop: 'level'
      },
      {
        label: '状态',
        prop: 'status',
        type: 'select',
        dicData: [
          {
            label: '未打印',
            value: 1
          },
          {
            label: '已打印',
            value: 2
          },
          {
            label: '已报废',
            value: 3
          },
          {
            label: '已使用',
            value: 4
          }
        ]
      },
      {
        label: '小包数量',
        prop: 'subPackQuantity'
      }
    ]
  };
};

export const getSmallPackOption = (self) => {
  return {
    height: 300,
    calcHeight: 30,
    border: true,
    index: true,
    indexLabel: '序号',
    viewBtn: false,
    selection: true,
    dialogClickModal: false,
    addBtn: false,
    editBtn: false,
    delBtn: false,
    tip: false,
    refreshBtn: false, //刷新按钮是否显示
    columnBtn: false, //控制表格列是否显示按钮是否显示
    menu: true,
    column: [
      {
        label: '包装条码',
        prop: 'sequenceNumber'
      },
      {
        label: '包装层级',
        prop: 'level'
      },
      {
        label: '状态',
        prop: 'status',
        type: 'select',
        dicData: [
          {
            label: '未打印',
            value: 1
          },
          {
            label: '已打印',
            value: 2
          },
          {
            label: '已报废',
            value: 3
          },
          {
            label: '已使用',
            value: 4
          }
        ]
      },
      {
        label: '包装数量',
        prop: 'quantity'
      }
    ]
  };
};
